package com.qianfeng.demo1.controller;

import com.qianfeng.demo1.util.MyException;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

//全局异常处理
@ControllerAdvice
public class AllExceptionHandler {
    @ExceptionHandler
    public String doException(Exception e, Model model){
        if (e instanceof MyException){
            String msg = e.getMessage();
            model.addAttribute("msg", msg);
            return "/error";
        }else {
            model.addAttribute("msg", "E100000");
            return "/error";
        }
    }
}
